<script>
function get_catform(){
	
	$('#cat_form').show()
	$('#cat').hide()
}
function get_compform(){
	$('#comp_form').show()
	$('#comp').hide()
}
function get_unitform(){
	$('#unit_form').show()
	$('#unit').hide()	
}

function close_catform(){
	
	$('#cat_form').hide()
	$('#cat').show()
}
function close_compform(){
	$('#comp_form').hide()
	$('#comp').show()
}
function close_unitform(){
	$('#unit_form').hide()
	$('#unit').show()
}

function check_category(name){
	$.post("<?= site_url('product/product/check_category')?>",{ name:name }, function(msg){
		if(msg!='0'){
			alert("Category Already Exists!!")
			$("#cat_name").val("")
			$("#cat_name").focus()
		}
	});
}
function check_company(name){
	$.post("<?= site_url('product/product/check_company')?>",{ name:name }, function(msg){
		if(msg!='0'){
			alert("Company Already Exists!!")
			$("#comp_name").val("")
			$("#comp_name").focus()
		}

	});
}
function check_unit(name){
	$.post("<?= site_url('product/product/check_unit')?>",{ name:name }, function(msg){
				if(msg!='0'){
			alert("Unit Already Exists!!")
			$("#unit_name").val("")
			$("#unit_name").focus()
		}
	});

}


</script>



<h2 style="background-color:#368EE0; color:white; font-size:20px; padding:5px;"> Create New Product </h2>
<p style="color:#7CB648;"align="justify"><b>Please enter the Product's information below.</b></p>

<div id="infoMessage"><?php echo $message;?></div>

<?php echo form_open("product/product/create_product");?>

     <table width="60%" align="center" class="table-condensed">  
        <tr> <td><b>  Product Name: </b></td>
            <td><?php echo form_input($name);?></td>
        </tr>  
       <tr> 
     	  <td> <b>Product Code:</b> </td>
    	  <td><?php echo form_input($code);?></td>
     </tr>   
         
       
        
      <tr>
         <td> <b> Category:</b> </td>
         <td id="cat">  <?php 
	 	$bl[0] = "";
	   		foreach($categories as $category){
				$bl[$category->id] = $category->name;
			}
			echo form_dropdown('id_category', $bl, '', 'class="chzn-select" data-placeholder="Choose a Category"  style="width:220px;"');  ?><a id="add_category" onclick="get_catform()">
								<i class='icon-plus'></i>
								</a>&nbsp;
								

	</td>
	<td id="cat_form" style="display: none" >
	<p>Category Name:<br>
	<input type="text" onchange="check_category(this.value);"  id="cat_name" name="cat_name">
	<a id="close_category" onclick="close_catform()">
								<i class='icon-minus'></i>
								</a></p>
	<p>Description:<br><input type="text" id="cat_desc" name="cat_desc"></p>
	</td>
    </tr>
  <tr>
         <td> <b> Company: </b></td> 
         <td id="comp">   <?php 
	 	$b2[0] = "";
	   		foreach($companies as $company){
				$b2[$company->id] = $company->name;
			}
			echo form_dropdown('id_company', $b2, '0', 'class="chzn-select" data-placeholder="Choose a Company" style="width:220px;"');  ?><a id="add_company" onclick="get_compform()">
								<i class='icon-plus'></i>
								</a>
								
	</td>     
    	<td id="comp_form" style="display: none" >
		<p>Company Name:<br>
		<input type="text" id="comp_name" onchange="check_company(this.value);" name="comp_name">
		<a id="close_company" onclick="close_compform()" >
								<i class='icon-minus'></i>
								</a></p>
	<p>Description:<br><input type="text" id="comp_desc" name="comp_desc"></p> 
	</td>
	  <tr>
         <tr>
         	 <td>  <b>Purchase Price:</b> </td>
             <td><?php echo form_input($purchase_price);?></td>
        </tr>   
     <tr> 
     	  <td> <b>Selling Price:</b> </td>
    	  <td><?php echo form_input($selling_price);?></td>
     </tr>   
     <tr> 
     	  <td> <b>Opening Stock:</b> </td>
    	  <td><?php echo form_input($opening_stock);?></td>
     </tr>   
       <tr>
         <td><b> Unit</b></td>
         <td id="unit">   <?php 
	 	$b3[0] = "";
	   		foreach($units as $unit){
				$b3[$unit->id] = $unit->name;
			}
			echo form_dropdown('id_unit', $b3, '0', 'class="chzn-select" data-placeholder="Choose a Unit" style="width:220px;"');  ?><a id="add_unit" onclick="get_unitform()" >
								<i class='icon-plus'></i>
								</a>
								
	</td>     
    	<td id="unit_form" style="display: none">
		<p>Unit Name:<br>
		<input type="text" id="unit_name" onchange="check_unit(this.value);"  name="unit_name">
		<a id="close_unit"  onclick="close_unitform()">
								<i class='icon-minus'></i>
								</a></p>
	<p>Description:<br><input type="text" id="unit_desc" name="unit_desc"></p> 
	</td>
</tr>
      <tr>
         <td><b> Branch</b></td>
         <td>   <?php 
	 	$b4[0] = "Warehouse";
	   		foreach($branches as $branch){
				$b4[$branch->id] = $branch->name;
			}
			echo form_dropdown('id_branch', $b4,"0",'class="chzn-select"  style="width:220px;"');  ?>
		</td>
	</tr>
	 <tr> 
     	  <td> <b>Alert Quantity:</b> </td>
    	  <td><?php echo form_input($alert_quantity);?></td>
     </tr>   
        
<tr><td>&nbsp;</td> <td>&nbsp;&nbsp;<?php echo form_submit('submit', 'Add Product', 'class="btn btn-info"');?></td></tr>
</table>
<?php echo form_close();?>




